//
//  HeaderView.m
//  MiaoTu
//
//  Created by dllo on 16/8/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MineHeaderView.h"
#import "UIImageView+WebCache.h"
#import "Items.h"
#import "UIView+Frame.h"

@interface MineHeaderView ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nicknameLabel;
@property (weak, nonatomic) IBOutlet UILabel *idLabel;
@property (weak, nonatomic) IBOutlet UILabel *wantGoLabel;
@property (weak, nonatomic) IBOutlet UILabel *likeCountLabel;
@property (weak, nonatomic) IBOutlet UILabel *likedCountLabel;
@property (weak, nonatomic) IBOutlet UIImageView *genderImageView;
@property (weak, nonatomic) IBOutlet UILabel *genderLabel;

@end

@implementation MineHeaderView

- (void)setLogin:(Login *)login {
    _login = login;
    Items *items = _login.Items;
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:items.HeadUrl] placeholderImage:[UIImage imageNamed:@"defaultHeadImage"]];
    _nicknameLabel.text = items.Nickname;
    _idLabel.text = [NSString stringWithFormat:@"ID:%ld", (long)items.Id];
    _wantGoLabel.text = [NSString stringWithFormat:@"想去%@", items.WantGo];
    _likeCountLabel.text = @(items.LikeCount).stringValue;
    _likedCountLabel.text = @(items.LikedCount).stringValue;
    if ([items.Gender isEqualToString:@"男"]) {
        _genderImageView.image = [UIImage imageNamed:@"man"];
    } else if ([items.Gender isEqualToString:@"女"]) {
        _genderImageView.image = [UIImage imageNamed:@"woman"];
    } else {
        NSLog(@"未知性别");
    }
    _genderLabel.text = @(items.Age).stringValue;
}

+ (instancetype)headerView {
    NSArray *nibView = [[NSBundle mainBundle] loadNibNamed:@"MineHeaderView" owner:self options:nil];
    return [nibView objectAtIndex:0];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [_headImageView layoutIfNeeded];
    _headImageView.layer.cornerRadius = _headImageView.dk_width / 2.0f;
    _headImageView.layer.masksToBounds = YES;
}

- (IBAction)editDataAction:(UIButton *)sender {
    self.sendButtonAction(MineHeaderClickEditData);
}

- (IBAction)likeDetailAction:(id)sender {
    self.sendButtonAction(MineHeaderClickLike);
}

- (IBAction)likedDetailAction:(id)sender {
    self.sendButtonAction(MineHeaderClickLiked);
}

- (IBAction)findFriendAction:(id)sender {
    self.sendButtonAction(MineHeaderClickFindFriend);
}


@end
